/**
 * @Project : ProgrammingExercises
 * @Package : Leetcode
 * @File : Q2535.java
 * @Author : WangRuoyu
 * @Date 2023/1/25 19:08
 */

package leetcode;

public class Q2535 {
    static int sumPos(int x) {
        int res = 0;
        while (x > 0) {
            res += (x % 10);
            x = x / 10;
        }
        return res;
    }

    public int differenceOfSum(int[] nums) {
        int p = 0;
        int q = 0;

        for (int num : nums) {
            p += num;
            q += sumPos(num);
        }

        if (p > q) {
            return p - q;
        } else {
            return q - p;
        }
    }

    public static void main(String[] args) {
        Q2535 sl = new Q2535();
        int[] nums = {1, 15, 6, 3};
        System.out.println(sl.differenceOfSum(nums));
    }
}
